package sol.leetcode;

import def.ListNode;
import utils.LinkedListUtils;

/**
 * Swap Nodes in Pairs
 */
public class Issue024 {
    public ListNode swapPairs(ListNode head) {
        if (null == head || null == head.next)
            return head;

        ListNode newHead = head.next, sub = newHead.next;
        newHead.next = head;
        head.next = swapPairs(sub);
        return newHead;
    }

    public static void main(String[] args) {
        ListNode head = LinkedListUtils.create();
        System.out.println(LinkedListUtils.print(head));

        Issue024 sol = new Issue024();
        System.out.println(LinkedListUtils.print(sol.swapPairs(head)));
    }
}
